﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace DGM.Util.Helpers.Json
{
    public static class JsonHelper
    {
        public static T GetWellKnownObjectFromJson<T>(string jsonString)  where T : new()
        {
            T result = JsonConvert.DeserializeObject<T>(jsonString);

            return result;
        }

        public static T GetWellKnownObjectFromJson<T>(JObject jsonObject) where T : new()
        {
            T result = JsonConvert.DeserializeObject<T>(jsonObject.ToString());

            return result;
        }

        public static string GetJsonFromWellKnownOjbect<T>(T wellKnownObject)
        {
            string json = JsonConvert.SerializeObject(wellKnownObject);

            return json;
        }
    }
}
